
/*

Dofile: table14_appendix.do 

Date: Dec. 10, 2016 
Aim: Interaction with a continuous measure 

Input: base_for_reg.dta 
Output: table14_appendix.xls 
Reported in the paper: "Table A.14: Regression Effective Marginal Tax Rate, Intra-firm, Arm’s length, and Mix transactions"

*/  

cd $datapath
use base_for_reg, clear 
sort iso3 
merge m:1 iso3 using remot 
keep if _m==3
drop _m 
egen c=group(pays) 
// pays is the iso2 code of the destination country 

egen fpt=group(siren nc8 type) 
// type is a dummy equal to one if the flow is intra-firm, siren is the firm id, nc8 is the 8-digit product category 


reg luv linveatr linvemtr
keep if e(sample) // allows to work from the same sample (same number of observations) with the two different tax ratess

replace intra_x=intra_x/100
sum intra_x,d 
foreach i in lgdpc ldist tarif dum_hines linvemtr{
g intra_`i'=`i'*intra_x
}


g tp=intra_x>0.99 
g medi=intra_x>0.01 & intra_x<0.99 

foreach i in lgdpc ldist tarif dum_hines linvemtr{
g tp_`i'=`i'*tp
g med_`i'=`i'*medi
}


*** Regs with two dummies 
global name tp_linvemtr // name of the xls file where the results are sent 
global tax_var tp_linvemtr med_linvemtr linvemtr // tax variable and its interaction 
areg luv type   $tax_var if tarif!=. , absorb(fpt) vce(cluster pays)
outreg2  type  $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    replace 

areg luv type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist  , absorb(fpt) vce(cluster pays)
outreg2  type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist   using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 

global tax_var tp_dum_hines med_dum_hines dum_hines
areg luv type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist , absorb(fpt) vce(cluster pays)
outreg2  type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist   using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2   append 

global tax_var tp_dum_hines dum_hines tp_linvemtr linvemtr med_dum_hines  med_linvemtr
areg luv type    $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist   , absorb(fpt) vce(cluster pays)
outreg2  type    $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist   using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2   append 

areg luv type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist if dum_hines==0, absorb(fpt) vce(cluster pays)
outreg2  type    $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 

global tax_var tp_dum_hines  tp_linvemtr med_dum_hines  med_linvemtr // level variables not included - absorbed by the FE 
reghdfe luv type  $tax_var tp_tarif tp_lgdpc tp_ldist med_tarif med_lgdpc med_ldist  if tarif!=. , absorb(fpt c) vce(cluster pays)
outreg2  type   $tax_var tp_tarif tarif tp_lgdpc lgdpc tp_ldist ldist med_tarif med_lgdpc med_ldist   using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 
